(function($){
	$.fn.extend({
		// toggle node's class by isVisible value
		switchClass: function(className, isVisible){
			return (isVisible) ? this.addClass(className) : this.removeClass(className);
		},
		// toggle nodes' show by isVisible value
		switchShow: function(isVisible){
			return (isVisible) ? this.show() : this.hide();
		},
		// sort cihldren node with compare function.
		sortChildren: function(compare){
			return this.each(function(){
				var arr = $.makeArray($(this).children());
				var result = $.isFunction(compare) ? arr.sort(compare) : arr.sort();
				$(arr).appendTo(this);
			});
		}
	});
	$.extend({
		fragment: {
			parse: function(uri){
				/** http://en.wikipedia.org/wiki/URI_scheme*/
				if (typeof uri == 'undefined') 
					uri = location.href;
				var params = {};
				var uriArray = uri.split("#");
				var param = (uriArray.length>1) ? uriArray[1] : uriArray[0];
				var paramArray = param.split("&");
				for (var i in paramArray) {
					var paramItem = paramArray[i].split("=");
					if (paramItem.length == 2) 
						params[decodeURIComponent(paramItem[0])] = decodeURIComponent(paramItem[1]);
				}
				return params;
			},
			
			make: function(hash){
				if(typeof hash != 'object')
					return;
				var resultArray = [];
				for (var key in hash) 
					resultArray.push(encodeURIComponent(key)+"="+encodeURIComponent(hash[key]));
				return resultArray.join("&");
			}
		}
	});
})(jQuery);
